#include "Project/MyLog.h"
using namespace MyLog;

int main()
{
    std::string syncloggername="sync-test";
    std::string asyncloggername="async-test";
    const LogLevel::Level limit=LogLevel::Level::DEBUG;

    std::unique_ptr<LoggerBuilder> builder(new LocalLoggerBuilder());
    builder->buildLoggerName(asyncloggername);
    builder->buildLogLevel(limit);
    builder->buildFormatter(PATTERN);
    builder->buildLogType(LoggerType::LOGGER_SYNC);
    builder->buildLogSink<StdOutSink>();
    builder->buildLogSink<FileSink>("./TestLog/test.log");
    builder->buildLogSink<RollSinkBySize>("./TestLog/test1.log");
    
}
void test2()
{
    std::ifstream ifs("./TestLog/test.log",std::ios::binary);
    assert(ifs.is_open());
    ifs.seekg(0,std::ios::end);
    std::size_t fsize=ifs.tellg();
    ifs.seekg(0,std::ios::beg);
    std::string body;
    body.resize(fsize);
    ifs.read(&body[0],fsize);
    assert(ifs.good());
    ifs.close();
    
    Buffer buffer;
    for(int i=0;i<body.size();i++)
    {
        buffer.push(&body[i],1);
    }
    std::ofstream ofs("./TestLog/temp.log",std::ios::binary);
    std::size_t len=buffer.readAbleSize();
    // ofs.write(buffer.begin(),len);
    for(int i=0;i<len;i++)
    {
        ofs.write(buffer.begin(),1);
        assert(ofs.good());
        buffer.moveReader(1);
    }
    ofs.close();

}
void test1()
{
    std::string loggername="sync-test";
    // Formatter::ptr fmt1(new Formatter());

    // LogSink::LogSinkshptr stdout_ptr=SinkFactory::CreateSink<StdOutSink>();
    // LogSink::LogSinkshptr File_ptr=SinkFactory::CreateSink<FileSink>("./TestLog/test.log");
    // LogSink::LogSinkshptr roll_ptr=SinkFactory::CreateSink<RollSinkBySize>("./testLog/roll-",1024*1024);
    // std::vector<LogSink::LogSinkshptr> sinks={stdout_ptr,File_ptr,roll_ptr};

    const LogLevel::Level limit=LogLevel::Level::DEBUG;

    std::unique_ptr<LoggerBuilder> builder(new LocalLoggerBuilder());
    builder->buildLoggerName(loggername);
    builder->buildLogLevel(limit);
    builder->buildFormatter(PATTERN);
    builder->buildLogType(LoggerType::LOGGER_SYNC);
    builder->buildLogSink<StdOutSink>();
    builder->buildLogSink<FileSink>("./TestLog/test.log");
    Logger::ptr s=builder->build();

    // Logger::ptr s(new SyncLogger(loggername,fmt1,sinks,limit));
    s->info(__FILE__,std::to_string(__LINE__),"%s","测试日志");
    s->debug(__FILE__,std::to_string(__LINE__),"%s","测试日志");

    s->error(__FILE__,std::to_string(__LINE__),"%s","测试日志");
    s->fatal(__FILE__,std::to_string(__LINE__),"%s","测试日志");
    s->warning(__FILE__,std::to_string(__LINE__),"%s","测试日志");
    // std::cout<<"hello\n";
    std::size_t cur_size=0,count=0;
    while(cur_size<1024*1024*5)
    {
        s->fatal(__FILE__,std::to_string(__LINE__),"测试日志count-%d",count++);
        cur_size+=20;
    }
}